
import Pagination from '@/components/pagination';
import mixin from '@/service/mixin';
import SelectAppList from '@/components/select-app-list';

export default {
    name: 'operation-operational-activities-activity-data',
    components: {
        Pagination,
        SelectAppList,
    },
    mixins: [mixin],
    data() {
        return {
            form: {
                userPhone: '',
                userId: '',
                appName: '',
                invitationCode: '',
                createTime:[]
            },
            rules: {
                userPhone: [],
                userId: [],
                invitationCode: [],
            },
            totalInfo: {
                fissionTotalCount: '--', // 拉新总人数
                loanTotalCount: '--', // 拉新总申请人数	是	[string]	查看
                loanSuccessTotalCount: '--',	// 拉新总放款成功人数	是	[string]	查看
                repaySuccessTotalCount: '--',	// 拉新总还款数	是	[string]	查看
                overdueTotalCount: '--',	// 拉新逾期总数	是	[string]	查看
                totalWithdrawnAmount: '--',	// 拉新总支出
            },
        };
    },
    methods: {
        // 获取列表数据
        getTableData(page = this.page) {
            const params = this.fillParams(page);
            this.$api.operation.fission.getUserFissionList(params).then(res => {
                const {status, data, error} = res;
                if ('1' === status && '00000000' === error && data) {
                    this.tableData = data.resultList || [];
                    this.totalInfo = data.totalInfo || {};
                    this.setPage(data.page, this.page);
                }
                this.tableMaxHeight = document.body.clientHeight - 290;
            });
        },
        // 搜索列表数据
        search() {
            this.page.currentPage = 1;
            this.getTableData();
        },
        // 导出列表数据
        exportExcel() {
            const params = this.fillParams();
            const user = this.$storage.get('user');
            const language = this.$storage.getLocal('language');
            params.language = language;
            params.token = user.token;
            const {$apiConf} = this;
            const url = this.$urlUtil.fillParams(params, $apiConf.baseUrl + $apiConf.urlType.operation.fission.exportFissionUserInfoExcel, ['page']);
            this.$openNewBlank(url);
        },
        // 配置查询和导出参数
        fillParams(page = this.page) {
            const form = this.form;
            const params = {
                userPhone: '',
                invitationCode: '',
                userId: '',
                appName: '',
                page: {
                    pageNo: page.currentPage,
                    pageSize: this.page.pageSize
                }
            };
            Object.keys(form).forEach(key => {
                if (typeof form[key] === 'string' && form[key]) {
                    form[key] = form[key].trim();
                    params[key] = form[key];
                }
            });
            if (form.createTime) {
                params.startCreateTime = form.createTime[0];
                params.endCreateTime = form.createTime[1];
            }
            return params;
        },
        // app列表
        appData(list) {
            if (list) {
                const domain = this.$storage.get('user').domain;
                if ('Pesopop' === domain) {
                    list.forEach(item => {
                        if (item.name === 'PesoHere') {
                            // 默认选中PesoHere
                            this.form.appName = 'PesoHere';
                        }
                    });
                } else {
                    const app = list[0] || {};
                    this.form.appName = app.name || '';
                }
                this.getTableData();
            }
        },
    },
    created() {
        // this.getTableData();
    }
}
